package com.zy.nettypoject.netty.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class TestFileChannel {
    public static void main(String[] args) throws Exception {
//        long start = System.currentTimeMillis();
//        FileChannel from = new FileInputStream("F:\\Test\\Test.zip").getChannel();
//        FileChannel to = new FileOutputStream("F:\\Test\\Test_我的.zip").getChannel();
//
//
//
//        //需要传输的文件大小
////        long size = from.size();
////        for (long left = size; left > 0;){
////            left -= from.transferTo(size - left, left, to);
////        }
//        from.transferTo(0,from.size(),to);
//        System.out.println("拷贝时间:"+(System.currentTimeMillis() - start)/1000);

        test1();
    }



    public static void test1() throws IOException {
        String path = "F:\\WORK\\admin_project\\vue3-antdv-admin";
        Files.walkFileTree(Paths.get(path),new SimpleFileVisitor<Path>(){
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                System.out.println("进入之前:"+dir);
                return super.preVisitDirectory(dir, attrs);
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                System.out.println(file);
                return super.visitFile(file, attrs);
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                return super.visitFileFailed(file, exc);
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                System.out.println("退出之后:"+dir);
                return super.postVisitDirectory(dir, exc);
            }
        });
    }
}
